﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<link rel="stylesheet" type="text/css" media="screen" href="css/jquery-ui-1.8.1.custom.css" />
<link rel="stylesheet" type="text/css" media="screen" href="css/ui.jqgrid.css" />
<script src="js/jquery-1.5.2.min.js" type="text/javascript"></script>
<script src="js/i18n/grid.locale-cn.js" type="text/javascript"></script>
<script src="js/json2.js" type="text/javascript"></script>
<script src="js/xing.js" type="text/javascript"></script>
<script type="text/javascript">
	$.jgrid.no_legacy_api = true;
	$.jgrid.useJSON = true;
</script>
<script src="js/jquery.jqGrid.min.js" type="text/javascript"></script>
<script type="text/javascript">
var myStreets = [];

function searchCustomer() {
	var district = $("#sf_district").val();
	var sid = $("#sf_street").val();
	var commuid = $("#sf_community").val();
	var ctype = $("#sf_ctype").val();
	var cid   = $("#sf_cid").val();
	var cname = $("#sf_cname").val();
	var q = "action=4&sf_district=" + district + "&sf_street=" + sid + "&sf_community=" + commuid + "&sf_ctype=" + ctype + "&sf_cid=<" + cid + ">&sf_cname=" + escape(cname);

	jQuery("#list1").jqGrid('setGridParam',{page:1,url:"main?" + q}).trigger("reloadGrid");
}

function sfDistrictChange() {
	var district = $("#sf_district").val();
	
	if (district == "0") {
		$("#sf_street").html("<option value='0'>选择街道</option>");
	} else {
		$("#sf_street").html("<option value='0'>全  部</option>" + initStreet(district));
		$("#sf_street").val("0");
	}
	$("#sf_community").html("<option value='0'>选择社区</option>");
}

function sfStreetChange() {
	var sid = $("#sf_street").val();
	
	if ((sid == null) || (sid.length == 1)) {
		$("#sf_community").html("<option value='0'>选择社区</option>");
	} else {
		$("#sf_community").html("<option value='0'>全  部</option>" + initCommunity(sid));
	}
}

function loadStreetCommunity() {
	$.get('base?action=12',function (data, textStatus){
		$.extend(true, myStreets, data);
	});
}

function initStreet(district) {
	var ops = "";
	for (i = 0; i < myStreets.length; i++) {
		if (myStreets[i].district != district)
			continue;
		ops += "<option value='" + myStreets[i].sid + "'>" + myStreets[i].sid + "|" + myStreets[i].sname + "</option>";
	}
	return ops;
}

function districtChange() {
	var district = $('#district').val();
	$("#sid").html(initStreet(district));
	var sid = $("#sid").val();
	$("#commuid").html(initCommunity(sid));
};

function streetChange() {
	var sid = $('#sid').val();
	$("#commuid").html(initCommunity(sid));
}

function initCommunity(sid) {
	var ops = "";
	for (var i = 0; i < myStreets.length; i++) {
		if (myStreets[i].sid != sid) 
			continue;
		var cs = myStreets[i].communitys;
		
		for (var j = 0; j < cs.length; j++) {
			ops += "<option value='" + cs[j].cid + "'>" + cs[j].cid + "|" + cs[j].cname + "</option>";
		}
	}

	//$("#commuid").html(ops);
	return ops;
}

function getRemark(rowId, val, rawObject, cm, rdata) {
	return "title = '" + rawObject[19] + "'";
}

function setGridButton() {
	jQuery("#list1").jqGrid('navGrid','#gridpager',{edit:false,add:false,del:false,refresh:false,search:false})
		.jqGrid('navButtonAdd','#gridpager',{
   		caption:"基本情况", 
   		buttonicon:"ui-icon-wrench", 
   		onClickButton: function(){
				var gr = jQuery("#list1").jqGrid('getGridParam','selrow');
				if( gr != null )
				  jQuery("#list1").jqGrid('editGridRow',gr,{
				  	editCaption:"添加/更改客户基本情况",
				  	bSubmit:"保存",modal: true,
				  	closeAfterEdit:true,
				  	viewPagerButtons:false, 
				  	reloadAfterSubmit:true,
				  	//beforeSubmit:checkValue,
				  	beforeShowForm:function(formid) {
				  		$('#cid').attr("readonly",true);
				  	},
				  	afterSubmit : function(r, postdata) {
				  					var data = eval('(' + r.responseText + ')');
				  					switch (data.code) {
			  							case 1: return [true, "添加/更改成功"]; break;
			  							default: return [false, data.message];
			  						}
				  	}
				  });
				else
					showTips("请选择要修改的客户");
			}
		});
}

function setGrid() {
	jQuery("#list1").jqGrid({ 
			url:'main?action=4',
			hidegrid: "false",
			datatype: "json",
			colNames:['客户编号','姓名','性别','特需','残疾类别','残疾等级','评估分数','残疾证号','家庭人数','住址','户口所在地','所属区','所属街道','所属社区','身体状况','账户余额','每月应冲值','资金来源','住房状况','培训需求','就业需求','康复需求','生活保障形式','养老','医疗','服务次数','托养服务类别','手机号码','固定电话','退出日期','基本情况'],
			colModel:[ 
					{name:'cid', width:95, sortable:false, align:'right',editable:true, cellattr: getRemark}, 
					{name:'cname', width:50, sortable:false, align:'right', cellattr: getRemark},
					{name:'csex',width:30, sortable:false, align:'right', formatter:'select', editoptions:{value:"F:女;M:男"}},
					{name:'specneed', width:30, sortable:false, align:'right', formatter:'checkbox',editrules:{required:true},editoptions: {value:"true:false"}},
					{name:'ctype',width:60, sortable:false, align:'right', formatter:'select', editoptions:{value:"1:视力残疾;2:听力残疾;3:言语残疾;4:肢体残疾;5:智力残疾;6:精神残疾;7:多重残疾"}},
					{name:'level',width:50, sortable:false, align:'right', edittype:"select", formatter:'select', editoptions:{value:"1:一级;2:二级;3:三级;4:四级"}, hidden:true},
					{name:'evalvalue',width:50, sortable:false, align:'right', formatter:'integer', editoptions:{size:3,maxlength:3},editrules:{required:true}, hidden:true},
					{name:'idcard', width:140, sortable:false, align:'right'},
					{name:'family', width:50, sortable:false, align:'right'},
					{name:'caddress',width:150, sortable:false, align:'right'},
					{name:'residence', width:80, sortable:false, align:'right'},
					{name:'district',width:50, sortable:false, align:'right', formatter:'select', editoptions:{value:"1:市辖区;2:桥东区;3:桥西区;4:高新区;5:宣化区;6:下花园区"}},
					{name:'sid', width:50, sortable:false, align:'right', hidden:true},
					{name:'commuid', width:80, sortable:false, align:'right', hidden:true},
					{name:'health', width:60, sortable:false, align:'right'},
					{name:'cursum', width:60, sortable:false, align:'right'},
					{name:'subsidy', width:70, sortable:false, align:'right', hidden:true},
					{name:'zjly',width:50, sortable:false, align:'right',formatter:'select', editoptions:{value:"1:中央;2:省级;3:市级;4:县区级"}, hidden:true},
					{name:'zfzk',width:50, sortable:false, align:'right', formatter:'select', editoptions:{value:"1:无房;2:危房;3:良好"}, hidden:true},
					{name:'peixun', width:50, sortable:false, align:'right', formatter:'checkbox',editrules:{required:true},editoptions: {value:"true:false"}, hidden:true},
					{name:'jiuye', width:50, sortable:false, align:'right', formatter:'checkbox',editrules:{required:true},editoptions: {value:"true:false"}, hidden:true},
					{name:'kangfu', width:50, sortable:false, align:'right', formatter:'checkbox',editrules:{required:true},editoptions: {value:"true:false"}, hidden:true},
					{name:'bzxs',width:50, sortable:false, align:'right', formatter:'select', editoptions:{value:"1:五保;2:低保;3:集中托养;4:亲属供养;5:无保障"}, hidden:true},
					{name:'yanglao',width:50, sortable:false, align:'right',formatter:'select', editoptions:{value:"1:新农合;2:城镇居民;3:无保险;4:其他"}, hidden:true},
					{name:'yiliao',width:50, sortable:false, align:'right', formatter:'select', editoptions:{value:"1:新农合;2:无保险;3:其他"}, hidden:true},
					{name:'servnum', width:50, sortable:false, align:'right'},
					{name:'tylb',width:80, sortable:false, align:'right',formatter:'select', editoptions:{value:"1:一类;2:二类;3:三类"}, hidden:true},
					{name:'cmobile', width:80, sortable:false, align:'right'},
					{name:'ctel', width:80, sortable:false, align:'right'},
					{name:'shiftdate', width:80, sortable:false, align:'right', hidden:true},
					{name:'remark', width:100, editable:true,edittype:"textarea",editoptions:{rows:"2",cols:"24"},editrules:{required:true}}
			], 
			viewrecords: true,
			rowNum:20,
			pager: '#gridpager',
			editurl:'main?action=27',
			subGrid: true,
			shrinkToFit: false,
			height: 460,
			width: 1300,
			footerrow: true,
			userDataOnFooter: true,
			caption:"客户信息",
			subGridRowExpanded: function(subgrid_id, row_id) {
				var subgrid_table_id, pager_id;
				subgrid_table_id = subgrid_id+"_t";
				subgridid = subgrid_table_id;
				pager_id = "p_"+subgrid_table_id;
				
				$("#"+subgrid_id).html("<table id='"+subgrid_table_id+"' class='scroll'></table><div id='"+pager_id+"' class='scroll'></div>");
				jQuery("#"+subgrid_table_id).jqGrid({
					url:"main?action=12&cid="+row_id,
					datatype: "json",
					colNames: ['工单号','客户编号','姓名','性别','客户类型','服务类型','服务内容','预约服务时间','服务状态','登记时间','派单时间'],
							colModel: [
										{name:'taskid', width:60, sortable:false, align:"right"},
										{name:'cid', width:100, sortable:false, align:"right"},
										{name:'cname', width:50, sortable:false, align:"right"},
										{name:'csex',width:30, sortable:false, align:"right", formatter:'select', editoptions:{value:"F:女;M:男"}},
										{name:'ctype',width:60, sortable:false, align:"right", editable:true,edittype:"select", formatter:'select', editoptions:{value:"1:视力残疾;2:听力残疾;3:言语残疾;4:肢体残疾;5:智力残疾;6:精神残疾;7:多重残疾"}},
										{name:'cservice',width:60, sortable:false, align:"right", formatter:'select',editoptions:{value:"0:新居开荒;1:家居保洁;2:办公室保洁;3:管道疏通;4:家电维修;5:电脑维修;6:装饰装修;7:家政服务;8:家教服务;9:票务服务;10:配送服务;11:搬家服务;12:开锁服务;13:房屋维修;14:其他"}},
										{name:'note', width: 260, sortable:false, align:"right"},
										{name:'ordertime', width:120, sortable:false, align:"right"},
										{name:'state',width:60, sortable:false,align:"right", edittype:"select", formatter:'select', editoptions:{value:"0:未分派;1:已分派;2:已开始;3:已完成;4:已冲正"}},
										{name:'rectime',  width:120, sortable:false, align:"right"},
										{name:'assigntime', width:120, sortable:false, align:"right"}
							],
							viewrecords: true,
							rowNum: 10,
							pager: pager_id, 
							height: '100%'
				});
			},
			subGridRowColapsed: function(subgrid_id, row_id) {
				// this function is called before removing the data
				var subgrid_table_id;
				subgrid_table_id = subgrid_id+"_t";
				jQuery("#"+subgrid_table_id).remove();
			}
	})}; 
	
	$(document).ready(function(){
		setGrid();
		loadStreetCommunity();
		$("#sf_district").val("0");
		$("#sf_submit").click(searchCustomer);
		$("#sf_street").live('change', sfStreetChange);
		setGridButton();
	});
</script>
<body style="background-color:#d9f1cc;">
									<form id="sf" action="main">
                	<table>
                	<tr>
	                	<td>选择所属区</td>
	                	<td><select id="sf_district" name="sf_district" onChange="sfDistrictChange()">
		                		<option value="0">全  市</option>
		                		<option value="1">市辖区</option>
		                		<option value="2">桥东区</option>
		                		<option value="3">桥西区</option>
		                		<option value="4">高新区</option>
		                		<option value="5">宣化区</option>
		                		<option value="6">下花园区</option>
		                	</select></td>
	                	<td>街道办事处 </td>
	                	<td><select id="sf_street" name="sf_street">
	                								<option value='0'>选择街道</option>
	                						 </select></td>
	                	<td>居委会</td>
	                	<td><select id="sf_community" name="sf_community"/>
	                						<option value='0'>选择社区</option>
	                				 </select></td>
	                	<td></td>
	                	<td>人员类型</td>
	                	<td><select id="sf_ctype" name="sf_ctype">
			                		<option value="0">全  部</option>
			                		<option value="1">视力残疾</option>
			                		<option value="2">听力残疾</option>
			                		<option value="3">言语残疾</option>
			                		<option value="4">肢体残疾</option>
			                		<option value="5">智力残疾</option>
			                		<option value="6">精神残疾</option>
			                		<option value="7">多重残疾</option>
			                	</select></td>
	                	<td>客户编号(*)</td>
	                	<td><input type="text" id="sf_cid" name="sf_cid" size="16" maxlength="13"/></td>
	                	<td>客户姓名</td>
	                	<td><input type="text" id="sf_cname" name="sf_cname" size="10" maxlength="4"/></td>
	                	<td><input type="button" id="sf_submit" value="查 询"></td>
                	</tr>
                	</table>
                	</form>
            
				<div id="RightPane"  >
					<div class="innertube">
					<table id="list1"></table>
					<div id="gridpager"></div>
				</div>
				</div>
</body>
